<!--[if lte IE 7]> <style type="text/css"> #entry_fields > div > label .arrow { display: inline; } </style> <![endif]-->

<div class="box">
    <div class="heading">
        <h1><img alt="" src="<?php echo base_url('assets/admin/images/review.png'); ?>"> Edit Page </h1>

        <div class="buttons">
            <a class="button" href="javascript:void(0);" id="save"><span>Save</span></a>
            <a class="button" href="javascript:void(0);" id="save_exit"><span>Save &amp; Exit</span></a>
            <a class="button" href="<?php echo base_url(ADMIN_PATH . '/pages'); ?>"><span>Cancel</span></a>
        </div>
    </div>
    <div class="content">
        <?php echo form_open(null, 'id="page_edit"'); ?>
        <div class="tabs">
            <ul class="htabs">
                <li><a href="#content-tab">Content</a></li>
                
                <li><a href="#page-tab">Page</a></li>
               
                <li><a href="#settings-tab">Settings</a></li>
            </ul>
			<div id="content-tab">
                <div id="entry_fields">
                    <div>
                        <?php echo form_label('<div class="arrow arrow_expand"></div><span class="required">*</span> Title', 'title'); ?>
                        <div>
                            <?php echo form_input(array('name'=>'title', 'id'=>'title', 'value'=>set_value('title',!empty($pagedetails['title']) ? $pagedetails['title'] : ''))); ?>
                        </div>
                    </div>
					<div>
                        <?php echo form_label('<div class="arrow arrow_expand"></div><span class="required">*</span> Slug', 'slug'); ?>
                        <div>
                            <?php echo form_input(array('name'=>'slug', 'id'=>'slug', 'value'=>set_value('slug',!empty($pagedetails['slug']) ? $pagedetails['slug'] : ''))); ?>
                        </div>
                    </div>
					<div>
                        <?php echo form_label('<div class="arrow arrow_expand"></div><span class="required">*</span> Content', 'content'); ?>
                        <div>
                            <?php 
								echo form_textarea(array('name'  => 'content','class' => 'ckeditor_textarea','id' => 'pagecontent','value'=>set_value('slug',!empty($pagedetails['content']) ? stripslashes($pagedetails['content']) : ''))); 
							?>
							
                        </div>
                    </div> 
                </div>
            </div>
			<!-- Page Tab -->
			<div id="page-tab">
				<div class="form">
					<div>
						<?php echo form_label('URL:', 'slug'); ?>
						<span style="line-height: 24px; "> <?php echo trim(base_url(), '/'); ?>/ </span>
						<?php echo form_input(array('id'=>'url_path','type'=>'hidden','name'=>'url_path','value'=>set_value('url_path',trim(base_url(), '/').'/'))); ?>
						<?php echo form_input(array('name'=>'url', 'type'=>'text','id'=>'url', 'value'=>set_value('url',!empty($pagedetails['slug']) ? $pagedetails['slug'] : ''))); ?>
					</div>
					<div>
						<?php echo form_label('Meta Title:<br /><span class="help">65 Characters Max</span>', 'meta_title'); ?>
						<?php echo form_input(array('name'=>'meta_title', 'id'=>'meta_title', 'class'=>'long', 'value'=>set_value('meta_title',!empty($pagedetails['meta_title']) ? $pagedetails['meta_title'] : ''))); ?>
						&nbsp;<span id="meta_title_count" class="help" style="display: inline;">(<?php echo strlen(set_value('meta_title','')); ?> Chars)</span>
					</div>
					<div>
						<?php echo form_label('Keywords:<span class="help">250 Characters Max</span>', 'meta_keywords'); ?>
						<?php echo form_textarea(array('name'=>'meta_keywords', 'id'=>'meta_keywords', 'style'=>'height: 50px;','value'=>set_value('meta_keywords',!empty($pagedetails['meta_keywords']) ? $pagedetails['meta_keywords'] : ''))); ?>
						&nbsp;<span id="meta_keywords_count" class="help" style="display: inline;">(<?php echo strlen(set_value('meta_keywords','')); ?> Chars)</span>
					</div>
					<div>
						<?php echo form_label('Description:<br /><span class="help">150 Characters Max</span>', 'meta_description'); ?>
						<?php echo form_textarea(array('name'=>'meta_description', 'id'=>'description_textarea', 'value'=>set_value('meta_description',!empty($pagedetails['meta_description']) ? $pagedetails['meta_description'] : ''))); ?>
						&nbsp;<span id="meta_description_count" class="help" style="display: inline;">(<?php echo strlen(set_value('meta_description','')); ?> Chars)</span>
					</div>
				</div>
			</div>
			<div id="settings-tab">
                <div class="form">
                    <div>
                        <?php echo form_label('<span class="required">*</span> Status:', 'status'); ?>
                        <?php echo form_dropdown('status', array('published'=>'Published', 'draft'=>'Draft', 'disabled' => 'Disabled' , 'deleted' => 'Deleted'), set_value('status',!empty($pagedetails['status']) ? $pagedetails['status'] : ''), 'id=\'status\'')?>
                    </div>
					<div>
                        <?php echo form_label('<span class="required">*</span> Template:', 'template'); ?>
                       
						<?php echo form_dropdown('template', array('page' => 'Page', 'blog' => 'Blog', 'homepage' => 'Homepage','contact'=>'Contact Form','landingpage'=>'Landing Page'),set_value('template',!empty($pagedetails['template']) ? $pagedetails['template'] : '') )?>
					</div>
                    <div>
                        <?php echo form_label('<span class="required">*</span> Date Created:', 'date_added'); ?>
                        <?php echo form_input(array('name'=>'date_added', 'class'=>'datetime', 'id'=>'date_added', 'value'=>set_value('date_added', !empty($pagedetails['date_added']) ? date('m/d/Y h:i:s a', strtotime($pagedetails['date_added'])) : date('m/d/Y h:i:s a')))); ?>
                    </div>

                </div>
            </div>
        </div>
        <?php echo form_close(); ?>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $( ".tabs" ).tabs();
		
		$('textarea.ckeditor_textarea').each(function(index)
		{
                ckeditor_config.height = $(this).height();
                CKEDITOR.replace('pagecontent', ckeditor_config); 
        });
		// Count meta title characters
        $('#meta_title').keyup( function() {
            $('#meta_title_count').html('(' + $(this).val().length + ' Chars)');
        });

        // Count keyword characters
        $('#meta_keywords').keyup( function() {
            $('#meta_keywords_count').html('(' + $(this).val().length + ' Chars)');
        });

        // Count description characters
        $('#description_textarea').keyup( function() {
            $('#meta_description_count').html('(' + $(this).val().length + ' Chars)');
        });
		
		
		// Auto Generate Url Title
		$('#title').keyup( function(e) {
			
			$('#url').val($(this).val().toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9\-_]/g, ''))
			$('#slug').val($(this).val().toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9\-_]/g, ''))
		});
		
		heading_pos = $('.heading').offset().top;
        position_top = false;

        $(window).scroll(function () {
            if (heading_pos - $(window).scrollTop() <= 0) {
                if (!position_top) {
                    $('.heading').addClass('position_top');
                    $('.content').addClass('position_top');
                    position_top = true;
                }
            } else {
                if (position_top) {
                    $('.heading').removeClass('position_top');
                    $('.content').removeClass('position_top');
                    position_top = false;
                }
            }
        });
		
		$("#save, #save_exit").click( function() {
			//alert( "ok");
            response = true;

            if ($('#status').val() != 'published')
            {
                response = confirm('When changing the page type from published ensure you do not have any published navigations or links to this page.\n\n Are you sure you want to continue?');
            }

            if (response)
            {
                if ($(this).attr('id') == 'save_exit')
                {
                    $('<input>').attr({
                        type: 'hidden',
                        name: 'save_exit',
                        value: '1'
                    }).appendTo('#page_edit');

                    $('#page_edit').submit();
                }
                else
                {
                    $('#page_edit').submit();
                }
            }
        });
       

    });
		 
</script>

